/**
 * 安卓白金英雄坛制作组 <br>
 * 文件名：NewButton.java <br>
 * 创建时间：2013-12-19 下午2:16:39 <br>
 * 所属项目：GmudEX <br>
 * @author 12548 <br>
 */
package lostland.gmud.exv2.ui.core;

import lostland.gmud.exv2.Assets;
import lostland.gmud.exv2.Game;
import lostland.gmud.exv2.blgframework.IPixmap;
import lostland.gmud.exv2.blgframework.impl.BLGGame;

/**
 * 类名：NewButton <br>
 * 说明：
 *
 * @author 12548
 */
public enum NewButton {
	NB_UP,
	NB_DOWN,
	NB_LEFT,
	NB_RIGHT,
	NB_ENTER,
	NB_BACK,
	NB_MENU,
	NB_NULL;

	public static boolean menubutton = true;
	public static int color = 0;

	private final int BOTTOM = 5;
	private final int LEFT = 5;
	private final int RIGHT = 5;
	private final int CENTER = 10;
	public static final int RADIUS = 32;

	public static boolean pressed[] = {false, false, false, false, false, false, false, false, false};

	public int x() {
		if (Game.classickeymap) {
			switch (this) {
				case NB_BACK:
					return BLGGame.FB2W - RIGHT - RADIUS * 2;
				case NB_DOWN:
					return LEFT + RADIUS * 2;
				case NB_ENTER:
					return BLGGame.FB2W - RIGHT - RADIUS * 3;
				case NB_LEFT:
					return LEFT + CENTER;
				case NB_RIGHT:
					return LEFT + RADIUS * 4 - CENTER;
				case NB_UP:
					return LEFT + RADIUS * 2;
				case NB_MENU:
					if (menubutton)
						return BLGGame.FB2W - RADIUS * 2 * 3 - RIGHT - CENTER * 2;
				default:
					return -1000;
			}
		} else {
			switch (this) {
				case NB_BACK:
					return BLGGame.FB2W - RADIUS * 2 * 7;
				case NB_DOWN:
					return BLGGame.FB2W - RADIUS * 2 * 2 - RIGHT - CENTER;
				case NB_ENTER:
					return BLGGame.FB2W - RADIUS * 2 - RIGHT;
				case NB_LEFT:
					return BLGGame.FB2W - RADIUS * 2 * 3 - RIGHT - CENTER * 2;
				case NB_RIGHT:
					return BLGGame.FB2W - RADIUS * 2 - RIGHT;
				case NB_UP:
					return BLGGame.FB2W - RADIUS * 2 * 2 - RIGHT - CENTER;
				case NB_MENU:
					if (menubutton)
						return BLGGame.FB2W - RADIUS * 2 * 3 - RIGHT - CENTER * 2;
				default:
					return -1000;
			}
		}
	}

	public int y() {
		if (Game.classickeymap) {
			switch (this) {
				case NB_BACK:
					return BLGGame.FB2H - BOTTOM - RADIUS * 4 - BOTTOM * 2;
				case NB_DOWN:
					return BLGGame.FB2H - BOTTOM - RADIUS * 2 - CENTER;
				case NB_ENTER:
					return BLGGame.FB2H - BOTTOM - RADIUS * 2 - BOTTOM;
				case NB_LEFT:
					return BLGGame.FB2H - BOTTOM - RADIUS * 4;
				case NB_RIGHT:
					return BLGGame.FB2H - BOTTOM - RADIUS * 4;
				case NB_UP:
					return BLGGame.FB2H - BOTTOM - RADIUS * 6 + CENTER;
				case NB_MENU:
					if (menubutton)
						return BOTTOM + 10;
				default:
					return -1000;
			}
		} else
			switch (this) {
				case NB_BACK:
					return BLGGame.FB2H - RADIUS * 2 - BOTTOM;
				case NB_DOWN:
					return BLGGame.FB2H - RADIUS * 2 - BOTTOM;
				case NB_ENTER:
					return BLGGame.FB2H - RADIUS * 6 - BOTTOM - CENTER * 2;
				case NB_LEFT:
					return BLGGame.FB2H - RADIUS * 2 - BOTTOM;
				case NB_RIGHT:
					return BLGGame.FB2H - RADIUS * 2 - BOTTOM;
				case NB_UP:
					return BLGGame.FB2H - RADIUS * 4 - BOTTOM - CENTER;
				case NB_MENU:
					if (menubutton)
						return BOTTOM + 10;
				default:
					return -1000;
			}
	}


	public IPixmap getPixmap() {
		return getPixmap(pressed[this.id()]);
	}

	public IPixmap getPixmap(boolean pressed) {
		if (this == NB_NULL) return null;

		if (pressed)
			return Assets.btns_pressed.get(colorstr[color] + namestr());
		else
			return Assets.btns.get(colorstr[color] + namestr());
	}

	public boolean inBound(int x, int y) {
		return ButtonControlledScreen.inbound(x(), y(), x, y);
	}

	public static NewButton inbound(int x, int y) {
		for (NewButton i : NewButton.values()) {
			if (ButtonControlledScreen.inbound(i.x(), i.y(), x, y))
				return i;
		}
		return NB_NULL;
	}


	public String namestr() {
		switch (this) {
			case NB_BACK:
				return "back";
			case NB_DOWN:
				return "down";
			case NB_ENTER:
				return "enter";
			case NB_LEFT:
				return "left";
			case NB_MENU:
				return "view";
			case NB_RIGHT:
				return "right";
			case NB_UP:
				return "up";
			case NB_NULL:
			default:
				return "";
		}
	}

	public static String statstr(boolean pressed) {
		if (pressed) return "pressed";
		else return "normal";
	}

	public static String colorstr[] = {"green", "red", "fire", "black", "touming"};

	public int id() {
		switch (this) {
			case NB_BACK:
				return 1;
			case NB_DOWN:
				return 2;
			case NB_ENTER:
				return 3;
			case NB_LEFT:
				return 4;
			case NB_MENU:
				return 5;
			case NB_NULL:
				return 0;
			case NB_RIGHT:
				return 6;
			case NB_UP:
				return 7;
			default:
				return 0;
		}
	}
}
